﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Dynamic;
using System.Linq;
using System.Threading.Tasks;
using ESoft.DataAccess;
using ESoft.DataAccess.EfCore;
using ESoft.Office.Excel.BO;
using ESoft.Office.Excel.Impl;
using ESoft.Service;
using Microsoft.AspNetCore.Mvc;
using SampleWeb2.Data.Models;
using SampleWeb2.Models;

namespace SampleWeb2.Controllers
{
    public class HomeController : Controller
    {
        private readonly IBaseService _baseService;
        private readonly ISqlRepositry _sqlRepositry;

        public HomeController(IBaseService baseService, ISqlRepositry sqlRepositry)
        {
            _baseService = baseService;
            _sqlRepositry = sqlRepositry;
        }
        public async Task<IActionResult> Index()
        {
            var exce = new ExcelService();
            
            var list = _baseService.FindEntities<GGoodsEntity>();
            var gs = _sqlRepositry.FindBySqlAsync<GGoodsEntity>("select GOODS_ID as GoodsId from g_goods",new ESoft.DataAccess.Models.PageInput(1,4), "GOODS_ID");
            ExportInputBo<GGoodsEntity> output=new ExportInputBo<GGoodsEntity>();
            
            await exce.ExportAsync(output);
            return View();
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
